/**
 * @param {number[][]} mat
 * @param {number} target
 * @return {number}
 */
var minimizeTheDifference = function(mat, target) {
  let set = new Set(mat[0]);
  let result = []
  for(let i=1;i<mat.length;i++){
    let sum = []
    for(let j=0;j<mat[0].length;j++){
      set.forEach(item=>{
        sum.push(item+mat[i][j])
      })
    }
    set = new Set([...sum])
  }
  console.log(set)
  set.forEach(item=>{
    result.push(Math.abs(item-target))
  })
  console.log(result)
  console.log(Math.min(...result))
  return Math.min(...result)
};

minimizeTheDifference([[1,2,3],[4,5,6],[7,8,9]],13)